1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.collect;
18
19 import static com.google.common.base.Preconditions.checkNotNull;
20
21 import com.google.common.annotations.GwtCompatible;
22
23 import java.util.Map;
24
25
26
27
28
29
30 @GwtCompatible
31 class SingletonImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
32 final R singleRowKey;
33 final C singleColumnKey;
34 final V singleValue;
35
36 SingletonImmutableTable(R rowKey, C columnKey, V value) {
37 this.singleRowKey = checkNotNull(rowKey);
38 this.singleColumnKey = checkNotNull(columnKey);
39 this.singleValue = checkNotNull(value);
40 }
41
42 SingletonImmutableTable(Cell<R, C, V> cell) {
43 this(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
44 }
45
46 @Override public ImmutableMap<R, V> column(C columnKey) {
47 checkNotNull(columnKey);
48 return containsColumn(columnKey)
49 ? ImmutableMap.of(singleRowKey, singleValue)
50 : ImmutableMap.<R, V>of();
51 }
52
53 @Override public ImmutableMap<C, Map<R, V>> columnMap() {
54 return ImmutableMap.of(singleColumnKey,
55 (Map<R, V>) ImmutableMap.of(singleRowKey, singleValue));
56 }
57
58 @Override public ImmutableMap<R, Map<C, V>> rowMap() {
59 return ImmutableMap.of(singleRowKey,
60 (Map<C, V>) ImmutableMap.of(singleColumnKey, singleValue));
61 }
62
63 @Override public int size() {
64 return 1;
65 }
66
67 @Override
68 ImmutableSet<Cell<R, C, V>> createCellSet() {
69 return ImmutableSet.of(
70 cellOf(singleRowKey, singleColumnKey, singleValue));
71 }
72
73 @Override ImmutableCollection<V> createValues() {
74 return ImmutableSet.of(singleValue);
75 }
76 }